﻿#region Using Directives

using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using EnvDTE;
using EnvDTE80;
using FeatureBuilder.ContribLib.Helpers;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TeamArchitect.PowerTools.Features;

#endregion

namespace FeatureBuilder.Contrib.Commands
{

    /// <summary>
    /// Feature Extension Command that does adds a Solution folder to the Solution.
    /// </summary>
    [DisplayName("Add Solution Folder")]
    [Description("Adds a Solution Folder to the current Solution")]
    [Category("IDE")]
    public class AddSolutionFolder : FeatureCommand
    {
        public string FolderName { get; set; }

        /// <summary>
        /// Gets the ServiceProvider that we will use to get a reference to DTE.
        /// </summary>
        [Import(typeof(SVsServiceProvider))]
        public IServiceProvider ServiceProvider { get; private set; }

        #region Overrides

        /// <summary>
        /// Called when any launch point bound to a command binding which refers to this command
        /// is invoked
        /// </summary>
        /// <param name="feature">Instance of Feature Extension which is invoking the command</param>
        public override void Execute()
        {
            DTE dte = this.ServiceProvider.GetService(typeof(DTE)) as DTE;

            try
            {
                Solution2 solution = dte.Solution as Solution2;

                if (DteHelper.FindSolutionFolderByPath(dte.Solution, FolderName) == null)
                {
                    solution.AddSolutionFolder(FolderName);
                }
            }
            catch { }
        }

        #endregion
    }
}